/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Xpath;

import DTO.TinTuc;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.io.IOException;
import java.net.URL;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Thieu Quang
 */
public class GetNews extends javax.swing.JFrame {

    ArrayList<TinTuc> tts = new ArrayList<TinTuc>();

    String link = "http://vnexpress.net/tin-tuc/the-gioi";

    /**
     * Creates new form GetNews
     */
    public GetNews() throws ClassNotFoundException, SQLException {
        initComponents();
        LoadForm();
        LoadTable();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuItem1 = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        txtPage = new javax.swing.JLabel();
        jButton_Previous = new javax.swing.JButton();
        btnNext = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jButton_LayTin = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jTextField_WebLink = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable_Category = new javax.swing.JTable();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem_New = new javax.swing.JMenuItem();
        jMenuItem_Manager = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        jMenuItem1.setText("jMenuItem1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Chương trình lấy tin");

        jPanel1.setToolTipText("");
        jPanel1.setName("Tin tức"); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(2000, 600));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 410, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 514, Short.MAX_VALUE)
        );

        txtPage.setText("Page");

        jButton_Previous.setText("Previous");
        jButton_Previous.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_PreviousMouseClicked(evt);
            }
        });
        jButton_Previous.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_PreviousActionPerformed(evt);
            }
        });

        btnNext.setText("Next");
        btnNext.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnNextMouseClicked(evt);
            }
        });
        btnNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNextActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(69, 69, 69)
                .addComponent(jButton_Previous)
                .addGap(46, 46, 46)
                .addComponent(txtPage)
                .addGap(40, 40, 40)
                .addComponent(btnNext)
                .addContainerGap(103, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPage)
                    .addComponent(jButton_Previous)
                    .addComponent(btnNext))
                .addContainerGap(36, Short.MAX_VALUE))
        );

        jButton_LayTin.setText("Lấy tin");
        jButton_LayTin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_LayTinActionPerformed(evt);
            }
        });

        jButton2.setText("Xóa chuyên mục");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextField_WebLink.setEditable(false);
        jTextField_WebLink.setColumns(10);
        jTextField_WebLink.setMaximumSize(new java.awt.Dimension(6, 20));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
                    .addComponent(jButton_LayTin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextField_WebLink, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField_WebLink, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jButton_LayTin)
                .addGap(18, 18, 18)
                .addComponent(jButton2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTable_Category.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTable_Category.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jTable_Category.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable_CategoryMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable_Category);

        jMenu1.setText("File");
        jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenu1MouseClicked(evt);
            }
        });

        jMenuItem_New.setText("Thêm trang");
        jMenuItem_New.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_NewActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem_New);

        jMenuItem_Manager.setText("Exit");
        jMenu1.add(jMenuItem_Manager);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 410, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(22, 22, 22)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 514, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(3, 3, 3))
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    private void jMenu1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu1MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenu1MouseClicked

    private void jMenuItem_NewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_NewActionPerformed
        // TODO add your handling code here:
        InputWebLink iwl = new InputWebLink(null, true);
        iwl.setVisible(true);
    }//GEN-LAST:event_jMenuItem_NewActionPerformed

    private void jButton_PreviousMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_PreviousMouseClicked


    }//GEN-LAST:event_jButton_PreviousMouseClicked

    private void btnNextMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnNextMouseClicked


    }//GEN-LAST:event_btnNextMouseClicked

    private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextActionPerformed
        // TODO add your handling code here:
        int Last = tts.size();// tong so tin
        int estpage = 0;
        if (Last % 3 == 0) {//neu tong tin chia he 4
            estpage = Last / 3;// uoc luong so trang
        } else {
            estpage = Last / 3 + 1;
        }
        int curpage = Integer.parseInt(txtPage.getText());// lay trang hien tai
        int k = 3;
        if ((curpage + 1) <= estpage) {// trang ke tiep khong duoc  trang uoc luong
            jPanel1.removeAll();// xoa toan bo container
            FlowLayout fl = new FlowLayout();
            jPanel1.setLayout(fl);// lay out cho panel chinh
            curpage++;
            if (curpage == estpage && Last % 3 != 0) {//Xac dinh so panel se them vao
                k = Last % 3;
            }
            txtPage.setText(String.valueOf(curpage));// ghi lai so trang
            JPanel pn[] = new JPanel[4];// panel cap1
            JPanel pnsub[] = new JPanel[4]; //panel cap 2
            BorderLayout bl[] = new BorderLayout[4];//layout cho panel cap 1
            GridLayout gl[] = new GridLayout[4];//layout cho panel cap 2
            JLabel image1[] = new JLabel[4];// title
            JLabel L1[] = new JLabel[4];// title
            JLabel L2[] = new JLabel[4];//date
            JTextArea T[] = new JTextArea[4];//dcription
            javax.swing.JScrollPane js[] = new javax.swing.JScrollPane[4];

            for (int i = 0; i < k; i++) {
  pn[i] = new JPanel();
                bl[i] = new BorderLayout();
                Dimension panesize = new Dimension(400, 170);
                pn[i].setPreferredSize(panesize);
                pn[i].setLayout(bl[i]);
                Image image = LoadImage(tts.get((curpage - 1) * 3 + i).getImage());
                ImageIcon img = new ImageIcon(scale(image));

                image1[i] = new javax.swing.JLabel("1");
                image1[i].setIcon(img);
                image1[i].setPreferredSize(new Dimension(80, 80));
                pn[i].add(image1[i], BorderLayout.WEST);
                pn[i].add(new javax.swing.JLabel("         "), BorderLayout.CENTER);
                pnsub[i] = new JPanel();
                pnsub[i].setPreferredSize(new Dimension(290, 170));
                gl[i] = new GridLayout(3, 1);
                FlowLayout fl2 = new FlowLayout();
                pnsub[i].setLayout(fl2);
                L1[i] = new JLabel(tts.get((curpage - 1) * 3 + i).getTitle());
                L2[i] = new JLabel(tts.get((curpage - 1) * 3 + i).getTime());
                T[i] = new JTextArea(tts.get((curpage - 1) * 3 + i).getDescrible());
                T[i].setLineWrap(true);
//                T[i].setTabSize(5);
//                T[i].setAutoscrolls(true);
                js[i] = new JScrollPane();
                T[i].setColumns(34);
                T[i].setRows(5);
                js[i].setViewportView(T[i]);
                pnsub[i].add(L1[i]);
                pnsub[i].add(L2[i]);
                pnsub[i].add(js[i]);
                pn[i].add(pnsub[i], BorderLayout.EAST);
                // quang cai panel cap2 vo cai panel cap 1
                jPanel1.add(pn[i]);
                // add vo cai panel chinh
            }
            jPanel1.revalidate();
            jPanel1.repaint();
            // noi chung la redraw con chi tiet ko ro
        }
    }//GEN-LAST:event_btnNextActionPerformed

    private void jButton_PreviousActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_PreviousActionPerformed
        // TODO add your handling code here:
        int Last = tts.size();
        int curpage = Integer.parseInt(txtPage.getText());
        if (curpage != 1) {// Page toi thieu la 1, xuong 0 se bi loi
            int k = 3;
            curpage--;
            jPanel1.removeAll();
            FlowLayout fl = new FlowLayout();
            jPanel1.setLayout(fl);
            txtPage.setText(String.valueOf(curpage));
            JPanel pn[] = new JPanel[4];
            JPanel pnsub[] = new JPanel[4];
            BorderLayout bl[] = new BorderLayout[4];
            JLabel image1[] = new JLabel[4];// title
            JLabel L1[] = new JLabel[4];// title
            JLabel L2[] = new JLabel[4];//date
            JTextArea T[] = new JTextArea[4];//dcription
            javax.swing.JScrollPane js[] = new javax.swing.JScrollPane[4];

            for (int i = 0; i < k; i++) {
                pn[i] = new JPanel();
                bl[i] = new BorderLayout();
                Dimension panesize = new Dimension(400, 170);
                pn[i].setPreferredSize(panesize);
                pn[i].setLayout(bl[i]);
                Image image = LoadImage(tts.get((curpage - 1) * 3 + i).getImage());
                ImageIcon img = new ImageIcon(scale(image));

                image1[i] = new javax.swing.JLabel("1");
                image1[i].setIcon(img);
                image1[i].setPreferredSize(new Dimension(80, 80));
                pn[i].add(image1[i], BorderLayout.WEST);
                pn[i].add(new javax.swing.JLabel("         "), BorderLayout.CENTER);
                pnsub[i] = new JPanel();
                pnsub[i].setPreferredSize(new Dimension(290, 170));
                FlowLayout fl2 = new FlowLayout();
                pnsub[i].setLayout(fl2);
                L1[i] = new JLabel(tts.get((curpage - 1) * 3 + i).getTitle());
                L2[i] = new JLabel(tts.get((curpage - 1) * 3 + i).getTime());
                T[i] = new JTextArea(tts.get((curpage - 1) * 3 + i).getDescrible());
                T[i].setLineWrap(true);
//                T[i].setTabSize(5);
//                T[i].setAutoscrolls(true);
                js[i] = new JScrollPane();
                T[i].setColumns(34);
                T[i].setRows(5);
                js[i].setViewportView(T[i]);
                pnsub[i].add(L1[i]);
                pnsub[i].add(L2[i]);
                pnsub[i].add(js[i]);
                pn[i].add(pnsub[i], BorderLayout.EAST);
                jPanel1.add(pn[i]);

                jPanel1.revalidate();
                jPanel1.repaint();
            }
        }
    }//GEN-LAST:event_jButton_PreviousActionPerformed

    private void jTable_CategoryMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable_CategoryMouseClicked
        try {
            // TODO add your handling code here:
            int index = -1;

            index = jTable_Category.getSelectedRow();
            //lay weblink
            link = jTable_Category.getValueAt(index, 2).toString();
            jTextField_WebLink.setText(link);
            LoadForm();
        } catch (SQLException ex) {
            Logger.getLogger(GetNews.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(GetNews.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jTable_CategoryMouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        try {
            // TODO add your handling code here:
            int kq = Function.DeleteCategory(link);
            LoadForm();
            LoadTable();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(GetNews.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(GetNews.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton_LayTinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_LayTinActionPerformed
        try {
            Function.GetNewsAgain(link);
            LoadForm();
        } catch (SQLException ex) {
            Logger.getLogger(GetNews.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(GetNews.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton_LayTinActionPerformed

    private Image scale(Image image) {
        //   this.image = image;

        return image.getScaledInstance(80, 80, Image.SCALE_DEFAULT);
    }

    /**
     * Load hình ảnh từ link
     *
     * @param link
     * @return
     */
    private Image LoadImage(String link) {
        Image image = null;
        try {
            URL url = new URL(link);
            image = ImageIO.read(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return image;
    }

    /**
     * Giao diện danh sách tin
     *
     * @throws SQLException
     * @throws ClassNotFoundException
     */
    private void LoadForm() throws SQLException, ClassNotFoundException {
        tts = Function.GetNewFormDatabase(link);
        if (tts.size() == 0) {
            return;
        }
        FlowLayout fl = new FlowLayout();
        jPanel1.setLayout(fl);
        int Last = tts.size();
        JPanel pn[] = new JPanel[4];
        JPanel pnsub[] = new JPanel[4];
        BorderLayout bl[] = new BorderLayout[4];
        JLabel image1[] = new JLabel[4];// title
        JLabel L1[] = new JLabel[4];// title
        JLabel L2[] = new JLabel[4];//date
        JTextArea T[] = new JTextArea[4];//dcription
        javax.swing.JScrollPane js[] = new javax.swing.JScrollPane[4];
        int curpage = 1;
        for (int i = 0; i < 3; i++) {
            pn[i] = new JPanel();
            bl[i] = new BorderLayout();
            Dimension panesize = new Dimension(400, 170);
            pn[i].setPreferredSize(panesize);
            pn[i].setLayout(bl[i]);

            Image image = LoadImage(tts.get((curpage - 1) * 3 + i).getImage());
            ImageIcon img = new ImageIcon(scale(image));

            image1[i] = new javax.swing.JLabel("1");
            image1[i].setIcon(img);
            image1[i].setPreferredSize(new Dimension(80, 80));
            pn[i].add(image1[i], BorderLayout.WEST);
            pn[i].add(new javax.swing.JLabel("         "), BorderLayout.CENTER);
            pnsub[i] = new JPanel();
            pnsub[i].setPreferredSize(new Dimension(290, 170));
            FlowLayout fl2 = new FlowLayout();
            pnsub[i].setLayout(fl2);
            L1[i] = new JLabel(tts.get((curpage - 1) * 3 + i).getTitle());
            L2[i] = new JLabel(tts.get((curpage - 1) * 3 + i).getTime());
            T[i] = new JTextArea(tts.get((curpage - 1) * 3 + i).getDescrible());
            T[i].setLineWrap(true);
//            T[i].setTabSize(5);
//            T[i].setAutoscrolls(true);
            js[i] = new JScrollPane();
            T[i].setColumns(34);
            T[i].setRows(5);
            js[i].setViewportView(T[i]);
            pnsub[i].add(L1[i]);
            pnsub[i].add(L2[i]);
            pnsub[i].add(add(js[i]));
            pnsub[i].setAutoscrolls(true);
            pn[i].add(pnsub[i], BorderLayout.EAST);

            // pn[i].add(new JSeparator(SwingConstants.VERTICAL));
            jPanel1.add(pn[i]);
            jPanel1.revalidate();

        }
        txtPage.setText("1");
    }

    private void LoadTable() throws SQLException, ClassNotFoundException {
        jTable_Category.setModel(Function.MakeTable());
        Hide();

    }

    private void Hide() {
        jTable_Category.getColumnModel().getColumn(0).setMinWidth(0);
        jTable_Category.getColumnModel().getColumn(0).setMaxWidth(0);
        jTable_Category.getColumnModel().getColumn(3).setMinWidth(0);
        jTable_Category.getColumnModel().getColumn(3).setMaxWidth(0);
    }

    /**
     * Dựng table động
     */
    public class rsTableModel extends AbstractTableModel {

        private Vector colHeaders;
        private Vector tbData;

        public rsTableModel(ResultSet rsData) throws SQLException {
            ResultSetMetaData rsMeta = rsData.getMetaData();    //-- Đọc MetaData của ResultSet
            int count = rsMeta.getColumnCount();              //-- Xác định số Field trong ResultSet

            colHeaders = new Vector(count);
            tbData = new Vector();
            for (int i = 1; i <= count; i++) {
                colHeaders.addElement(rsMeta.getColumnName(i));
            }
            while (rsData.next()) {
                Vector dataRow = new Vector(count);
                for (int i = 1; i <= count; i++) {
                    dataRow.addElement(rsData.getObject(i));
                }
                tbData.addElement(dataRow);
            }
        }

        public int getColumnCount() {
            return colHeaders.size();
        }

        public int getRowCount() {
            return tbData.size();
        }

        public Object getValueAt(int row, int column) {
            Vector rowData = (Vector) (tbData.elementAt(row));
            return rowData.elementAt(column);
        }

        public String getColumnName(int column) {
            return (String) (colHeaders.elementAt(column));
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GetNews.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GetNews.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GetNews.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GetNews.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new GetNews().setVisible(true);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(GetNews.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(GetNews.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnNext;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton_LayTin;
    private javax.swing.JButton jButton_Previous;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem_Manager;
    private javax.swing.JMenuItem jMenuItem_New;
    public javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable_Category;
    private javax.swing.JTextField jTextField_WebLink;
    private javax.swing.JLabel txtPage;
    // End of variables declaration//GEN-END:variables
}
